package com.jiantong.work.impl.service.yangzhibaoxian;

/**
 * Created by ThinkPad on 2017/9/5.
 */


import com.google.common.base.Throwables;
import com.jiantong.work.impl.dao.yangzhibaoxian.ClaimsLossDao;
import com.jiantong.work.impl.dao.yangzhibaoxian.InsuranceApplicationDao;
import com.jiantong.work.model.yangzhibaoxian.Bankcard;
import com.jiantong.work.model.yangzhibaoxian.ClaimsLoss;
import com.jiantong.work.service.yangzhibaoxian.ClaimsLossService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.PageInfo;
import io.terminus.common.model.Paging;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 定损表现场勘查
 */
@Slf4j
@Service
@RpcProvider
public class ClaimsLossServiceImpl implements ClaimsLossService{

    private ClaimsLossDao claimsLossDao;

    @Autowired
    public ClaimsLossServiceImpl(ClaimsLossDao claimsLossDao) {
        this.claimsLossDao = claimsLossDao;
    }



    @Override
    public Response<ClaimsLoss> findById(Long id) {
        try {
            ClaimsLoss claimsLoss = (ClaimsLoss) claimsLossDao.findById(id);
            if (claimsLoss == null) {
                log.error("claimsLoss(id={}) is not found", id);
                return Response.fail("claimsLoss.not.found");
            }

            return Response.ok(claimsLoss);
        } catch (Exception e) {
            log.error("failed to find claimsLoss(id={}), cause:{}", id, Throwables.getStackTraceAsString(e));
            return Response.fail("claimsLoss.find.fail");
        }
    }

    @Override
    public Response<List<ClaimsLoss>> findByIds(List ids) {
        try {
            List<ClaimsLoss> claimsLossList=  claimsLossDao.findByIds(ids);
            if (claimsLossList == null) {
                log.error("claimsLossList(ids={}) is not found", ids);
                return Response.fail("claimsLossList.not.found");
            }

            return Response.ok(claimsLossList);
        } catch (Exception e) {
            log.error("failed to find claimsLossList(ids={}), cause:{}", ids, Throwables.getStackTraceAsString(e));
            return Response.fail("claimsLossList.find.fail");
        }

    }

    @Override
    public Response<List<ClaimsLoss>> list(Map map) {
        try {
            List<ClaimsLoss> claimsLossList=  claimsLossDao.list(map);
            if (claimsLossList == null) {
                log.error("claimsLossList(ids={}) is not found", map);
                return Response.fail("claimsLossList.not.found");
            }

            return Response.ok(claimsLossList);
        } catch (Exception e) {
            log.error("failed to find bankcardList(ids={}), cause:{}", map, Throwables.getStackTraceAsString(e));
            return Response.fail("claimsLossList.find.fail");
        }
    }

    @Override
    public Response<Paging<ClaimsLoss>> ping(Integer offset, Integer limit, Map map) {
        try {
            PageInfo pageInfo=new PageInfo(offset,limit);
            Paging<ClaimsLoss> claimsLossPaging=  claimsLossDao.paging(pageInfo.getOffset(), pageInfo.getLimit(),map);
            if (claimsLossPaging == null) {
                log.error("claimsLossPaging(ids={}) is not found", map);
                return Response.fail("claimsLossPaging.not.found");
            }

            return Response.ok(claimsLossPaging);
        } catch (Exception e) {
            log.error("failed to find bankcardList(ids={}), cause:{}", map, Throwables.getStackTraceAsString(e));
            return Response.fail("claimsLossPaging.find.fail");
        }
    }

    @Override
    public Boolean update(ClaimsLoss claimsLoss) {
        try {
            Boolean b=claimsLossDao.update(claimsLoss);
            return b;
        }catch (Exception e){
            return false;
        }
    }

    @Override
    public Long create(ClaimsLoss claimsLoss) {
        try {
            claimsLossDao.create(claimsLoss);
            return claimsLoss.getId();
        }catch (Exception e){
            e.printStackTrace();
            return -500L;
        }
    }

    @Override
    public Integer creates(List<ClaimsLoss> claimsLossList) {
        try {

            return  claimsLossDao.creates(claimsLossList);
        }catch (Exception e){
            e.printStackTrace();
            return -500;
        }
    }
}
